from django.db import models
from django.contrib.auth.models import User

from ..models import Article


class ArticleComment(models.Model):
    article = models.ForeignKey(Article, related_name='comments')
    comment = models.CharField(max_length=500)
    date = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(User, related_name='article_comments')
    parent = models.ForeignKey('self', null=True, blank=True, related_name='children')

    class Meta:
        ordering = ('date', 'pk')

    def __str__(self):
        return '{0} - {1}'.format(self.user.profile, self.article.title)
